package com.itheima.reggie.utils;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;

/**
 * 短信发送工具类
 */
public class SMSUtils {

    /**
     * 发送短信
     * @param signName 签名
     * @param templateCode 模板
     * @param phoneNumbers 手机号
     * @param param 参数
     */
    public static void sendMessage(String signName, String templateCode,String phoneNumbers,String param){
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GHhatiznGG52T5EidAW", "xOFzvwf7G8jPhL3eNpyOmjPjFRZJfx");
        IAcsClient client = new DefaultAcsClient(profile);

        SendSmsRequest request = new SendSmsRequest();
        request.setSysRegionId("cn-hangzhou");
        request.setPhoneNumbers(phoneNumbers);
        request.setSignName(signName);
        request.setTemplateCode(templateCode);
        request.setTemplateParam("{\"code\":\""+param+"\"}");
        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println("====发送的状态信息====》"+response.getMessage());
        }catch (ClientException e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {
        /**
         * 参数一：签名
         * 参数二： 模板的编号
         * 参数三： 接收人手机号
         * 参数四：验证码
         */
        //生成一个四位验证码
        String code = ValidateCodeUtils.generateValidateCode4String(4);
        sendMessage("黑马旅游网","SMS_205126318","13767754950",code);
        //sendMessage("黑马旅游网","SMS_205126318","13415144207",code);
        System.out.println("验证码是："+code);
    }
}
